# 文件储存工具
import qiniu


access_key = 'yV4GmNBLOgQK-1Sn3o4jktGLFdFSrlywR2C-hvsW'
secret_key = 'bixMURPL6tHjrb8QKVg2tm7n9k8C7vaOeQ4MEoeW'
bucket_name = 'ihome'


def upload_file(data):
    """
    上传文件到骑牛云
    上传文件是二进制

    """
    q = qiniu.Auth(access_key, secret_key)
    token = q.upload_token(bucket_name)
    ret, info = qiniu.put_data(token, None, data)

    if info.status_code != 200:
        raise Exception('骑牛上船失败')

    return ret['key']